<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>便民药店系统</title>
<meta http-equiv="x-ua-compatible" content="IE=10,9,8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="便民药店系统" />
<link rel="apple-touch-icon-precomposed" href="static/images/i/edu.png">

<link rel="stylesheet" href="static/js/LayuiCMS2.0/layui/css/layui.css"
	media="all" />
<link rel="stylesheet" href="static/js/LayuiCMS2.0/css/public.css"
	media="all" />

<script src="static/js/date.format.js"></script>
<style type="text/css">
.layui-form-item .layui-input-inline {
	width: 215px;
}
</style>
</head>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox">
			<form class="layui-form">
				<div class="layui-form-item">
					<!-- <div class="layui-inline">
						<label class="layui-form-label">记录时间</label>
						<div class="layui-inline">
							<input type="text" id="start"  autocomplete="off" class="layui-input" placeholder="请选择记录开始时间"/>

						</div>
						<div class="layui-inline">
							--
						</div>
						<div class="layui-inline">
							<input type="text" id="end" autocomplete="off" class="layui-input" placeholder="请选择记录结束时间">

						</div>
					</div> -->
					<div class="layui-inline">
						<label class="layui-form-label">姓名</label>
						<div class="layui-input-inline">
							<input type="text" autocomplete="off" id="name"
								class="layui-input" placeholder="请输入用户姓名">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">身份证号</label>
						<div class="layui-input-inline">
							<input type="text" autocomplete="off" id="idCard"
								class="layui-input searchVal" placeholder="请输入用户身份证号">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">用户名</label>
						<div class="layui-input-inline">
							<input type="text" autocomplete="off" id="userName"
								class="layui-input searchVal" placeholder="请输入用户用户名">
						</div>
					</div>
					<div class="layui-btn-group">
						<button type="button" class="layui-btn search_btn">
							查询&nbsp;<i class="layui-icon">&#xe615;</i>
						</button>
						&nbsp;
						<button type="button" class="layui-btn layui-icon-add-1 add_btn">
							新增&nbsp;<i class="layui-icon">&#xe654;</i>
						</button>
					</div>
				</div>
			</form>
		</blockquote>
		<table id="newsList" lay-filter="newsList"></table>

		<!--操作-->
		<script type="text/html" id="newsListBar">	
			<a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>
			<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="del">删除</a>
		</script>
	</form>
	<script type="text/javascript"
		src="static/js/LayuiCMS2.0/layui/layui.js"></script>
	<script type="text/javascript">
	layui.use(['form','layer','laydate','table','laytpl'],function(){
	    var form = layui.form,
	        layer = parent.layer === undefined ? layui.layer : top.layer,
	        $ = layui.jquery,
	        laydate = layui.laydate,
	        laytpl = layui.laytpl,
	        table = layui.table;

		laydate.render({
			elem: '#start',
			type: 'date',
			trigger : "click",
			done : function(value, date, endDate){
				submitTime = value;
			}
		});

		laydate.render({
			elem: '#end',
			type: 'date',
			trigger : "click",
			done : function(value, date, endDate){
				submitTime = value;
			}
		});

	    //新闻列表
	    var tableIns = table.render({
	        elem: '#newsList',
	        url : '${pageContext.request.contextPath }/admin/getAdminUserList',
	        cellMinWidth : 95,
	        page : true,
	        height : "full-185",
	        limit : 10,
	        limits : [10,15,20,25],
	        id : "newsListTable",
	        cols : [[
				{field: 'name', title: '姓名', width:180, align:"center"},
	            {field: 'idCard', title: '身份证号', width:240, align:"center"},
	          /*   {field: 'deptName', title: '科室名称', width:240, align:"center"}, */
	            {field: 'userName', title: '用户名', align:"center", width:120},
				{field: 'phone', title: '联系电话', align:"center", width:180},
			/*	{field: 'opApplyNo', title: '手术申请号', align:"center", width:180},*/
				{field: 'recordTime', title: '记录时间', align:'center', templet:function(d){
						if(d.recordTime == null){
							return "";
						}
						return new Date(d.recordTime).format("yyyy-MM-dd hh:mm:ss");
					}
				},
	            {title: '操作', width:120, templet:'#newsListBar', fixed:"right", align:"center"}
	        ]]
	    });
	
	
	    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
	    $(".search_btn").on("click",function(){

	    	var name = $("#name").val();
	    	var idCard = $("#idCard").val();
			var userName = $("#userName").val();


	        if(name || idCard || userName){
	        	
	        	alert(name+"-"+idCard+"-"+userName);
	            table.reload("newsListTable",{
	            	url:'${pageContext.request.contextPath }/admin/getAdminUserList',
	                page: {
	                    curr: 1 //重新从第 1 页开始
	                },
	                where: {

						name: name,  //搜索的关键字
						idCard:idCard,
						userName: userName
	                }
	            });
	        }else{
	            layer.msg("请输入搜索的内容");
	        }
	    });

		$(".add_btn").click(function(){
			addBasic();
		});
	
	    //添加文章
	    function addBasic(){
	    	var content = "${pageContext.request.contextPath }/admin/adminUserAddPage";
	        var index = layui.layer.open({
	            title : "添加用户",
	            type : 2,
	            content : content,
	            success : function(layero, index){
	                var body = layui.layer.getChildFrame('body', index);
	                setTimeout(function(){
	                    layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
	                        tips: 3
	                    });
	                },500);
	            }
	        });
	        layui.layer.full(index);
	        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
	        $(window).on("resize",function(){
	            layui.layer.full(index);
	        });
	    }

		//添加文章
		function updateBasic(edit){
			var content = "${pageContext.request.contextPath }/admin/adminUserAddPage?adminUserId=" + edit.id;
			var index = layui.layer.open({
				title : "查看用户",
				type : 2,
				content : content,
				success : function(layero, index){
					var body = layui.layer.getChildFrame('body', index);
					setTimeout(function(){
						layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
							tips: 3
						});
					},500);
				}
			});
			layui.layer.full(index);
			//改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
			$(window).on("resize",function(){
				layui.layer.full(index);
			});
		}

		function viewBasic(edit){
			var content = "${pageContext.request.contextPath }/ops/applyOperationUpdate?applyOperationId=" + edit.id + "&serialNumberId=" + edit.serialNumber + "&view=1";
			var index = layui.layer.open({
				title : "添加信息",
				type : 2,
				content : content,
				success : function(layero, index){
					var body = layui.layer.getChildFrame('body', index);
					setTimeout(function(){
						layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
							tips: 3
						});
					},500);
				}
			});
			layui.layer.full(index);
			//改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
			$(window).on("resize",function(){
				layui.layer.full(index);
			});
		}

	    //列表操作
	    table.on('tool(newsList)', function(obj){
	        var layEvent = obj.event,
	            data = obj.data;
	
	        if(layEvent === 'edit'){ //编
				updateBasic(data);
	        }else if(layEvent === 'view'){
				viewBasic(data);
			}else if(layEvent === 'del'){
				 layer.confirm('确认要删除该用户吗?', function(index){
					
						
		               $.ajax({
		                        url:'${pageContext.request.contextPath }/admin/delAdminUserById',
		                        type:'get',
		                        data:{'id':data.id},//向服务端发送删除的id
		                        success:function(result){
		                        	 if(result!=null){
		      	                       var data = $.parseJSON(result);
		      	                       if(data.code == "1"){
		      	                           setTimeout(function(){
		      	                        	 	obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
				                                layer.close(index);
				                                console.log(index);
				                                layer.msg("删除成功",{icon:1});
		      	                           },500);
		      	                       }else{
		      	                    	   layer.msg("删除失败",{icon:5});
		      	                           return false;
		      	                       }

		      	                   } 
		                       }
		                        	
		   
		             });
		             layer.close(index); 
		        });
			}
	    });
	
	});
	</script>
</body>
</html>
